package com.nacos.client.controller;

import com.nacos.client.feignClient.ServiceFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
@RequestMapping("client2")
@RestController
public class ClientServiceController {
    @Autowired
    RestTemplate restTemplate;
    @Value("${service-url.nacos-user-service}")
    private String serviceUrl;
    @GetMapping("/client/service")
    public String getService(){
        return restTemplate.getForObject(serviceUrl+"/getPort", String.class);
    }
    @Autowired
    private DiscoveryClient discoveryClient;

    @GetMapping("/check-instances")
    public List<ServiceInstance> checkInstances() {
        return discoveryClient.getInstances("service");
    }
    @Autowired
    ServiceFeign serviceFeign;
    @GetMapping("/serviceFeignPort")
    public String serviceFeignPort(){
        return serviceFeign.getPortService();
    }
    @GetMapping("/serviceFeignMessage")
    public String serviceFeignMessage(){
        return serviceFeign.test();
    }
}
